<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("comctrls.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Vehicle_Journal_Create extends Page
{
       public $lblcost = null;
       public $JSValidate = null;
       public $hfError = null;
       public $chkBusiness = null;
       public $lblref = null;
       public $lbldesc = null;
       public $lblincident = null;
       public $Label12 = null;
       public $edIncidentNum = null;
       public $Label1 = null;
       public $Label2 = null;
       public $dpDate = null;
       public $btnShowCat = null;
       public $cmbdriver = null;
       public $Label6 = null;
       public $Label4 = null;
       public $memoComments = null;
       public $Label3 = null;
       public $edRefNum = null;
       public $edCompLiability = null;
       public $lblMobile = null;
       public $edDesc = null;
       public $cmbType = null;
       public $lblJob = null;
       public $lblBirthdate = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $compid = null;
       public $JTDivCat = null;
       public $JTGroupBox1 = null;
       public $btnAddCat = null;
       public $btnDelCat = null;
       public $edCat = null;
       public $listCat = null;
       public $JTSiteTheme1 = null;
       public $imgBack = null;
       public $Image3 = null;
       public $hiddenId = null;
       function edRefNumJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edRefNum','lblref');
       <?php

       }

       function edCompLiabilityJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edCompLiability','lblcost');
       <?php

       }

       function edDescJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edDesc','lbldesc');
       <?php

       }

       function edIncidentNumJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edIncidentNum','lblincident');
       <?php

       }

       function Vehicle_Journal_CreateJSLoad($sender, $params)
       {
       $this->clr_journal();
       ?>
       //Add your javascript code here

       <?php

       }

       function btnDelCatJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var dropdownIndex = document.getElementById('listCat').selectedIndex;
       var dropdownValue = document.getElementById('listCat')[dropdownIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxCat3(dropdownValue,comp);
       <?php

       }

       function btnAddCatJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addcat = document.getElementById('edCat').value;
       var comp = document.getElementById('compid').value;
       AjaxCat2(addcat,comp);
       document.Vehicle_Journal_Create.edCat.value = "";
       <?php

       }


       function btnShowCatJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
      document.getElementById('JTDivCat').Show();
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }


       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php
       }

       function clr_journal()
       {
       $this->dpDate->Text=date('Y-m-d');
       $this->edDesc->Text="";
       $this->edCompLiability->Text="";
       $this->edRefNum->Text="";
       $this->memoComments->Text="&nbsp";

       $this->cmbdriver->Clear();
       $this->cmbdriver->AddItem('--Select--', null, null);
       $this->cmbdriver->setItemIndex('--Select--', null, null);
       $result_driver = mysql_query("select * from employee_tbl where company_id='".$_SESSION['company_id']."' and veh_op='1'");

       while($row_driver = mysql_fetch_array($result_driver))
        {
            $this->cmbdriver->AddItem($row_driver['lname'].','.$row_driver['fname'], null, $row_driver['lname'].','.$row_driver['fname']);
        }
       }

        function validateRequired($value, $lbl)
       {
          if($value == '' || $value == null)
          {
             $this->$lbl->Caption = '&darr This field is required &darr';
             $this->hfError->setValue('1');
          }
       }

       function Vehicle_Journal_CreateCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $id = $_GET['veh'];
       $this->hiddenId->setValue($id);

       $this->hfError->setValue('0');
       $this->lblref->Caption = '';
       $this->lblcost->Caption ='';
       $this->lblincident->Caption ='';
       $this->lbldesc->Caption = '';

       $this->dpDate->Text="";
       $this->edDesc->Text="";
       $this->edCompLiability->Text= date('Y-m-d');
       $this->edRefNum->Text="";
       $this->memoComments->Text="&nbsp";

       $this->cmbType->Clear();
       $result_journal = mysql_query("select * from lookup_vehicle_tbl where company_id = '".$_SESSION['company_id']."' AND category='journal categories'");

       while($row_journal = mysql_fetch_array($result_journal))
        {
            $this->cmbType->AddItem($row_journal['value'], null, $row_journal['value']);
        }

       //list type
       $result_cat = mysql_query("select * from lookup_vehicle_tbl where company_id = '".$_SESSION['company_id']."' AND category='journal categories'");

       while($row_cat = mysql_fetch_array($result_cat))
        {
            $this->listCat->AddItem($row_cat['value'], null, $row_cat['value']);
        }

       $this->cmbdriver->Clear();
       $this->cmbdriver->AddItem('--Select--', null, null);
       $result_driver = mysql_query("select * from employee_tbl where company_id='".$_SESSION['company_id']."' and veh_op='1'");

       while($row_driver = mysql_fetch_array($result_driver))
        {
            $this->cmbdriver->AddItem($row_driver['lname'].','.$row_driver['fname'], null, $row_driver['lname'].','.$row_driver['fname']);
        }


       $this->imgBack->setLink('details_emission.php?layer=1&veh='.$this->hiddenId->getValue());
       }

       function btnCancelClick($sender, $params)
       {
       redirect('details_emission.php?layer=1&veh='.$this->hiddenId->getValue());



       }



       function btnSubmitClick($sender, $params)
       {
       $this->validateRequired($this->edCompLiability->Text, 'lblcost');
       $this->validateRequired($this->edIncidentNum->Text, 'lblincident');
       $this->validateRequired($this->edRefNum->Text, 'lblref');
       $this->validateRequired($this->edDesc->Text, 'lbldesc');
       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {

       $result = mysql_query("insert into veh_incident_tbl (vehicle_id,
       company_id,
       date,
       incident_num,
       type,
       description,
       driver,
       cost,
       ref_num,
       comments)

       values ('".$this->hiddenId->getValue()."',
       '".$_SESSION['company_id']."',
       '".$this->dpDate->Text."',
       '".$this->edIncidentNum->Text."',
       '".$this->cmbType->getItemIndex()."',
       '".$this->edDesc->Text."',
       '".$this->cmbdriver->getItemIndex()."',
       '".$this->edCompLiability->Text."',
       '".$this->edRefNum->Text."',
       '".$this->memoComments->Text."')");

       redirect('details_emission.php?layer=1&veh='.$this->hiddenId->getValue());

        }
       }


}

global $application;

global $Vehicle_Journal_Create;

//Creates the form
$Vehicle_Journal_Create=new Vehicle_Journal_Create($application);

//Read from resource file
$Vehicle_Journal_Create->loadResource(__FILE__);

//Shows the form
$Vehicle_Journal_Create->show();

?>